package com.spic.business.plan.drill.service.impl;

import java.util.ArrayList;
import java.util.List;
import com.spic.common.core.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.spic.business.plan.drill.mapper.PlanDrillPerformAssessMapper;
import com.spic.business.plan.drill.domain.PlanDrillPerformAssess;
import com.spic.business.plan.drill.service.IPlanDrillPerformAssessService;

/**
 * 应急预案演练评估Service业务层处理
 *
 * @author renxiang
 * @date 2021-10-31
 */
@Service
public class PlanDrillPerformAssessServiceImpl implements IPlanDrillPerformAssessService
{
    @Autowired
    private PlanDrillPerformAssessMapper planDrillPerformAssessMapper;

    /**
     * 查询应急预案演练评估
     *
     * @param id 应急预案演练评估主键
     * @return 应急预案演练评估
     */
    @Override
    public PlanDrillPerformAssess selectPlanDrillPerformAssessById(Long id)
    {
        return planDrillPerformAssessMapper.selectPlanDrillPerformAssessById(id);
    }

    /**
     * 查询应急预案演练评估列表
     *
     * @param planDrillPerformAssess 应急预案演练评估
     * @return 应急预案演练评估
     */
    @Override
    public List<PlanDrillPerformAssess> selectPlanDrillPerformAssessList(PlanDrillPerformAssess planDrillPerformAssess)
    {
        return planDrillPerformAssessMapper.selectPlanDrillPerformAssessList(planDrillPerformAssess);
    }

    /**
     * 新增应急预案演练评估
     *
     * @param planDrillPerformAssess 应急预案演练评估
     * @return 结果
     */
    @Override
    public int insertPlanDrillPerformAssess(PlanDrillPerformAssess planDrillPerformAssess)
    {
        PlanDrillPerformAssess assess = new PlanDrillPerformAssess();
        assess.setDrillNumber(planDrillPerformAssess.getDrillNumber());
        List<PlanDrillPerformAssess> assessList = new ArrayList<PlanDrillPerformAssess>();
        assessList =  planDrillPerformAssessMapper.selectPlanDrillPerformAssessList(assess);
        if(assessList.isEmpty()){
            planDrillPerformAssess.setCreateTime(DateUtils.getNowDate());
            return planDrillPerformAssessMapper.insertPlanDrillPerformAssess(planDrillPerformAssess);
        }else {
            planDrillPerformAssess.setUpdateTime(DateUtils.getNowDate());
            return planDrillPerformAssessMapper.updatePlanDrillPerformAssess(planDrillPerformAssess);
        }
    }

    /**
     * 修改应急预案演练评估
     *
     * @param planDrillPerformAssess 应急预案演练评估
     * @return 结果
     */
    @Override
    public int updatePlanDrillPerformAssess(PlanDrillPerformAssess planDrillPerformAssess)
    {
        planDrillPerformAssess.setUpdateTime(DateUtils.getNowDate());
        return planDrillPerformAssessMapper.updatePlanDrillPerformAssess(planDrillPerformAssess);
    }

    /**
     * 批量删除应急预案演练评估
     *
     * @param ids 需要删除的应急预案演练评估主键
     * @return 结果
     */
    @Override
    public int deletePlanDrillPerformAssessByIds(Long[] ids)
    {
        return planDrillPerformAssessMapper.deletePlanDrillPerformAssessByIds(ids);
    }

    /**
     * 删除应急预案演练评估信息
     *
     * @param id 应急预案演练评估主键
     * @return 结果
     */
    @Override
    public int deletePlanDrillPerformAssessById(Long id)
    {
        return planDrillPerformAssessMapper.deletePlanDrillPerformAssessById(id);
    }
}
